from django.shortcuts import render,HttpResponse,redirect
from .models import *
# Create your views here.
    # 学生添加
def addstudent(request):
    if request.method=='GET':
        return render(request,'studentadd.html')
    elif request.method=='POST':
        name=request.POST.get('name')
        sex=request.POST.get('sex')
        dateofbirth=request.POST.get('dateofbirth')
        contactway=request.POST.get('contactway')
        nowclass=request.POST.get('nowclass')
        teacher=request.POST.get('teacher')
        a=Student(name=name,sex=sex,dateofbirth=dateofbirth,contactway=contactway,nowclass=nowclass,teacher_id=teacher)
        a.save()
        return redirect(show)
#老师添加
def addteacher(request):
    if request.method=='GET':
        return render(request,'teacheradd.html')
    elif request.method=='POST':
        name=request.POST.get('name')
        sex=request.POST.get('sex')
        dateofbirth=request.POST.get('dateofbirth')
        contactway=request.POST.get('contactway')
        position=request.POST.get('position')
        a=Teacher(name=name,sex=sex,dateofbirth=dateofbirth,contactway=contactway,position=position)
        a.save()
        return redirect(show)
# 展示所有学生信息
def show(request):
    show1=Student.objects.all()
    return render(request,'show.html',context={'show1':show1})
def delete(request,student_id):
    student_id = Student.objects.get(id=student_id)
    student_id.delete()
    return redirect('show')